package com.gitee.ywj1352;

import com.alibaba.nacos.api.annotation.NacosInjected;
import com.alibaba.nacos.api.config.ConfigService;
import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacos.api.naming.NamingService;
import org.springframework.stereotype.Service;


@Service
public class NamingServiceDemo {

    @NacosInjected
    private NamingService namingService;

    @NacosInjected
    private ConfigService configService;

    public void demoRegisterService() {
        try {
            namingService.registerInstance("test-service", "127.0.0.1", 9999);
        } catch (NacosException e) {
            e.printStackTrace();
        }
    }

    public void getConfig(){
            String dataId = "TEST_YWJ";
            String groupId = "G_YWJ";
            String content = null;
            try {
                content = configService.getConfig(dataId, groupId, 5000);
            } catch (NacosException e) {
                e.printStackTrace();
            }
            System.out.println(content);
    }

}
